/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simrace;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 *
 * @author Eyo
 */
public class Race {
    
    public static final int rounds = 8;
    public static final int cars = 3;
    
    List<Car> allCars = new ArrayList<>();
    
    public Race(){
               
    }
    
    public void startRace(){
        for(Car car : allCars){
            car.start();
        }
    }
    
    public void addCar(Car car){
        allCars.add(car);
    }
    
    private boolean endOfRace(){
        for(Car car : allCars){
            if(car.getLap() <= Race.rounds){
                return false;
            }
        }
        return true;
    }
    
    public void sortAllCars(){
     if (endOfRace()) {
        System.out.println("**** Endstand ****");
        Collections.sort(allCars, new Comparator<Car>() {
            public int compare(Car o1, Car o2) {return Integer.compare(o1.roundTime(), o2.roundTime());}
        });
        int i = 1;
        for (Car car : allCars)
            System.out.println(i++ + ". Platz: Wagen " + car.getCarName() + " Zeit: " + car.roundTime());
        }
    }
    
}
